#!/usr/bin/env bash
 
line="$(grep -nHr '^%package.*-n.*python2' | head -n 1)"
name="$(echo "$line" | awk -F ':' '{print $3}' | awk '{print $NF}')"
num="$(echo "$line" | awk -F ':' '{print $2}')"
num=$((++num))
sed -i -e "${num}i%py2_migration_meta ${name}" *.spec

if ! rpmspec -P *.spec > /dev/null ; then
	git reset --hard
	echo "$PWD" >> /tmp/failed
	exit 1
fi
